//2009/08/18 00:27:16
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <sstream>
#include <algorithm>

using namespace std;

class GradingSystem
{
public:
    int fairness(vector <int> scores, vector <int> grades)
    {
		int n = scores.size();
		int sum = 0;
		for(int i=0; i<n; i++)
		{
			int mmax = grades[i];
			int mmin = grades[i];
			for(int j=0; j<n; j++)
			{
				if(scores[i] >= scores[j]) mmax = max(mmax, grades[j]);
				if(scores[i] <= scores[j]) mmin = min(mmin, grades[j]);
			}
			sum += mmax - mmin;
		}
		return sum;
    }
};
